<?php
require_once "sprder.php";


class zksd extends sprder{


	private $_zksd_url = "http://zhekousudi.com/city/shenzhen/default_1_brand.aspx?brandid=";
	private $_curren_id = 1;
	
	
	function __construct() {
		$url = explode("/",$this->_zksd_url);
		array_pop($url);
		$this->_url = implode('/',$url);
		

	}
	function start(){
		
		while(true){
			
			$url = $this->_zksd_url.$this->_curren_id;
			$content = $this->getWebContent($url);
			//print_r($content);exit;
			//'<table cellspacing="0" rules="all" border="1" id="ctl00_ctl00_ContentPlaceHolder1_ContentPlaceHolder2_GridView1"';
			preg_match("/<table\s+cellspacing=\"0\"\s+rules=\"all\"\s+border=\"1\"\s+id=\"ctl00_ctl00_ContentPlaceHolder1_ContentPlaceHolder2_GridView1\"\s+width=\"581\"\s+style=\".*\">([\d\D]*)<\/table>\s*<\/div>/",$content,$rs);
			//preg_match_all("/<td\s+align=\"[a-z]+?\"\s+valign=\"middle\"\s+nowrap=\"nowrap\">(.*)<\/td>/",$content,$rs);
			
			$content = $rs[1];
			
			preg_match_all("/<td\s+align=\"[a-z]+?\"\s+valign=\"middle\"\s+nowrap=\"nowrap\">([\d\D]*?)<\/td>/",$content,$rs);
			//preg_match_all("/<tr>\S*<td.*nowrap=\"nowrap\">([\d\D]*?)<\/td>\s*<td.*nowrap=\"nowrap\">([\d\D]*?)<\/td><td.*nowrap=\"nowrap\">([\d\D]*?)<\/td><td.*nowrap=\"nowrap\">([\d\D]*?)<\/td><td.*nowrap=\"nowrap\">([\d\D]*?)<\/td><td.*nowrap=\"nowrap\">([\d\D]*?)<\/td>/",$content,$rs);
			$content = $rs[1];
			
			if(empty($content)){
				//echo "empty array!";
				//break;
			}
			//数据保存
			$this->saveZksd($content);
			
			
			$this->_curren_id++;
		}
	}
	function saveZksd($data){
		$i = 1;
		$arr = array();
		foreach($data as $k=>$v){
			if($i%7==0){
				preg_match("/href=\"(.*?)\"[\d\D]*?>([\d\D]*)<\/a>/",$arr[2],$arr2);
				$url = $this->_url.'/'.$arr2[1];
				$arr[2] = $arr2[2];
				
				$arr[3] = strip_tags($arr[3]);
				$arr[4] = strip_tags($arr[4]);
				$arr[4] = str_replace("/","-",$arr[4]);
				
				//$arr[2] = iconv("UTF8","gb2312",$arr[2]);
				//echo mb_detect_encoding($arr[3]);
				//exit;
				
				$arrData = array(
					"name"=>$arr[0],
					"cate"=>$arr[1],
					"company"=>$arr[2],
					"intro"=>$arr[3],
					"getDate"=>$arr[4],
					"floor"=>$arr[5],
					"createDate"=>date("Y-m-d H:i:s")
				);
				if(strtotime($arr[4]) >= strtotime("2012-06-03")){
					print_r($arrData);exit;
					$db = new M_zksd();
					$db->insertData($arrData);
					$this->getZksdDetail($url);
				}
				$i = 1;
				unset($arr,$arrData);
			}
			$arr[] = $v;
			unset($data[$k]);
			$i++;
		}
	}
	function getZksdDetail($url){
		
		
	}
	function __destruct() {


	}
}


?>